// pages/taskDetaily/taskDetaily.js
const app = getApp();
let taskId;

Page({
  /**
   * 页面的初始数据
   */
  data: {
    score: 0, 
    evalDesc:'',
    // 1:待接取 2:已下架 3:已完成 4:已取消 (接取四个状态)
    // 5:审核中 6:待接取 7:已下架 8:已取消 9:已完成(发布任务五个状态)
    taskStatus:-1,//接取的任务 (待接取)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self = this;
    taskId = options.taskId;
    wx.request({
      url:app.globalData.prefix+"/taskAction/publishTaskInfo.do?taskId="+taskId+"&openId="+app.globalData.userInfo.openId,
      success:function(res){
        console.log(res.data.result);
        self.setData({task:res.data.result.task});
        let taskImage = res.data.result.task.taskImage;
        let imageArr = taskImage.split(";");
        self.setData({takeList:res.data.result.takeList});
        self.setData({imageArr:imageArr});
        self.setData({eval:res.data.result.eval}); 
      }
    });
  },

  giveUp() {
    wx.showModal({
      title: '提示',
      content: '您确定要放弃接取任务？',
      success (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.navigateTo({
            url: '../taskDetaily/taskDetaily'
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  //重新编辑
  toEdit() {
    wx.navigateTo({
      url: '../publishMerge/publish?taskId='+taskId
    })
  },
  // 重新发布
  rePublish() {
    wx.switchTab({
      url: '../publish/publish'
    })
  },
  //去截稿
  toDown() {
    wx.navigateTo({
      url: '../taskStop/taskStop?taskId='+taskId,
    })
  },

  evalTask(e){
    let self = this;
    console.log("评价如下："+self.data.score);
    console.log(self.data.evalDesc);
    wx.request({
      url:app.globalData.prefix+"/taskAction/taskEval.do?taskId="+taskId+"&taskScore="+self.data.score+"&taskEval="+self.data.evalDesc,
      success:function(e){
        if(e.data.status!='00'){
          wx.$showToast(e.data.errorMsg);
          return;
        }
        wx.$showToast("评价成功");
        wx.navigateTo({
          url: '../mySelfTask/mySelfTask',
        })
      }
    });
  },

  showStar(e){
    this.setData({score:e.detail.value});
  },

  inputEvalDesc(e){
    console.log(e.detail.value);
    this.setData({evalDesc:e.detail.value});
  },

  toDelete() {
    console.log(app.globalData.openId);
    wx.request({
      url:app.globalData.prefix+"/taskAction/deleteTask.do?taskId="+taskId+"&openId="+app.globalData.userInfo.openId,
      success:function(res){
        if(res.data.status!='00'){
          wx.$showToast(res.data.errorMsg);
          return;
        }
        wx.$showToast(res.data.result);
        wx.navigateTo({
          url: '../mySelfTask/mySelfTask'
        })
      }
    });
  },

  toPay() {
    wx.navigateTo({
      url:'../payMoney/payMoney?taskId='+taskId
    })
  },

  toMemberInfo(e) {
    let memberId = e.currentTarget.dataset.memberid;
    wx.navigateTo({
      url: '../employDetaily/employDetaily?memberId='+memberId,
    })
  },
 
  cancleTask() {
    wx.showModal({
      title:'提示',
      content:'确认取消任务吗？',
      success:function(res){
        if(res.success){
          wx.request({
            url:app.globalData.prefix+"/taskAction/cancelTask.do?taskId="+taskId+"&openId="+app.globalData.userInfo.openId,
            success:function(res){
              if(res.data.status!="00"){
                wx.$showToast(res.data.errorMsg);
                return;
              }
              wx.$showToast(res.data.result);
              wx.navigateTo({
                url:'../mySelfTask/mySelfTask'
              })
            }
          });
        }
      }
    })
  }
})